package com.zlict.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.enums.BusinessType;
import com.zlict.admin.domain.RdPortfolioAssets;
import com.zlict.admin.service.IRdPortfolioAssetsService;
import com.zlict.common.utils.poi.ExcelUtil;
import com.zlict.common.core.page.TableDataInfo;

/**
 * 资产管理-组合资产Controller
 * 
 * @author lqh
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/assets/portfolioAssets")
@RequiredArgsConstructor
public class RdPortfolioAssetsController extends BaseController
{
    private final IRdPortfolioAssetsService rdPortfolioAssetsService;

    /**
     * 查询资产管理-组合资产列表（分页）
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdPortfolioAssets rdPortfolioAssets)
    {
        startPage();
        List<RdPortfolioAssets> list = rdPortfolioAssetsService.selectRdPortfolioAssetsList(rdPortfolioAssets);
        return getDataTable(list);
    }

    /**
     * 导出资产管理-组合资产列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:export')")
    @Log(title = "资产管理-组合资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RdPortfolioAssets rdPortfolioAssets)
    {
        List<RdPortfolioAssets> list = rdPortfolioAssetsService.selectRdPortfolioAssetsList(rdPortfolioAssets);
        ExcelUtil<RdPortfolioAssets> util = new ExcelUtil<RdPortfolioAssets>(RdPortfolioAssets.class);
        util.exportExcel(response, list, "资产管理-组合资产数据");
    }

    /**
     * 获取资产管理-组合资产详细信息
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rdPortfolioAssetsService.selectRdPortfolioAssetsById(id));
    }

    /**
     * 新增资产管理-组合资产
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:add')")
    @Log(title = "资产管理-组合资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdPortfolioAssets rdPortfolioAssets)
    {
        return toAjax(rdPortfolioAssetsService.insertRdPortfolioAssets(rdPortfolioAssets));
    }

    /**
     * 修改资产管理-组合资产
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:edit')")
    @Log(title = "资产管理-组合资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdPortfolioAssets rdPortfolioAssets)
    {
        return toAjax(rdPortfolioAssetsService.updateRdPortfolioAssets(rdPortfolioAssets));
    }

    /**
     * 删除资产管理-组合资产
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:remove')")
    @Log(title = "资产管理-组合资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdPortfolioAssetsService.deleteRdPortfolioAssetsByIds(ids));
    }

    /**
     * 查询资产管理-组合资产列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:portfolioassets:getList')")
    @GetMapping("/getList")
    public AjaxResult getList(RdPortfolioAssets rdPortfolioAssets)
    {
        List<RdPortfolioAssets> list = rdPortfolioAssetsService.selectRdPortfolioAssetsList(rdPortfolioAssets);
        return success(list);
    }

    /**
     * 据组合资产查询添加过的仪器设备/建筑物列表
     */
    @GetMapping("/getPortfolioDetailListById")
    public TableDataInfo getPortfolioDetailListById(RdPortfolioAssets rdPortfolioAssets){
        startPage();
        List<RdPortfolioAssets> list = rdPortfolioAssetsService.getPortfolioDetailListById(rdPortfolioAssets);
        return getDataTable(list);
    }

    /**
     * 根据组合资产查询未添加过的仪器设备/建筑物列表
     */
    @GetMapping("/getFixedAssetsListById")
    public AjaxResult getFixedAssetsListById(RdPortfolioAssets rdPortfolioAssets){
        List<RdPortfolioAssets> list = rdPortfolioAssetsService.getFixedAssetsListById(rdPortfolioAssets);
        return success(list);
    }

    /**
     * 批量启用
     */
    @PostMapping("/batchEnable")
    public AjaxResult batchEnable(@RequestBody Long[] ids)
    {
        return toAjax(rdPortfolioAssetsService.batchEnable(ids));
    }

    /**
     * 批量禁用
     */
    @PostMapping("/batchDisable")
    public AjaxResult batchDisable(@RequestBody Long[] ids)
    {
        return toAjax(rdPortfolioAssetsService.batchDisable(ids));
    }
}
